package A03_稀疏数组和队列.A32_队列;

/**
 * @Author: KingWang
 * @Date: 2021/6/1
 * @Desc:
 **/
public class Queue {

    private String[] queue = null;
    private int front = -1;
    private int rear = -1;
    private int maxSize = 10;

    public Queue(int maxSize){
        this.maxSize = maxSize;
        this.queue = new String[maxSize];
    }

    public boolean isFull(){
        return rear == maxSize-1;
    }

    public boolean isEmpty(){
        return rear ==  front;
    }

    public void add(String e){
        if(isFull()){
            System.out.println("队列已满");
            return;
        }
        rear++;
        queue[rear] = e;

    }

    //取出来一个
    public String pop(){
        if(isEmpty()){
            System.out.println("队列为空");
        }
        front++;
        return queue[front];
    }

    public void show(){
        if(isEmpty()){
            System.out.println("队列为空");
            return;
        }
        int start = front < 0 ? 0 : front;
        for(int i=start;i<=rear;i++){
            System.out.println("序号"+i+"==>" + queue[i]);
        }
    }

}
